package com.cykj.user.controller;

import com.cykj.common.core.web.controller.BaseController;
import com.cykj.common.core.web.domain.AjaxResult;
import com.cykj.user.service.IScanLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/scan")
public class ScanLoginController extends BaseController {

    @Autowired
    private IScanLoginService scanLoginService;

    @PostMapping("/generate")
    public AjaxResult generateQrCode() {
        return success(scanLoginService.generateQrCode());
    }

    @GetMapping("/check")
    public AjaxResult checkScanStatus(@RequestParam String scanId) {
        return success(scanLoginService.checkScanStatus(scanId));
    }

    @PostMapping("/confirm")
    public AjaxResult confirmScan(@RequestParam String scanId, 
                                 @RequestHeader("Authorization") String token) {
        boolean result = scanLoginService.confirmScan(scanId, token);
        return result ? success() : error("确认扫码登录失败");
    }

    @GetMapping("/status")
    public AjaxResult getScanStatus(@RequestParam String scanId) {
        return success(scanLoginService.getScanStatus(scanId));
    }
}